﻿using System.Collections.Generic;
using PMngr.Data;

namespace PMngr.Main
{
    public partial class SingleApprovalForm : BaseApproval
    {
        private IRepository repository;

        public SingleApprovalForm(IRepository repository, IEnumerable<int> selecteds)
        {
            this.repository = repository;

            Approved = approvalDt =>
            {
                if (selecteds != null)
                {
                    foreach (var id in selecteds)
                    {
                        var userId = id;
                        var profile = repository.Find<Profile>(userId);
                        profile.ApprovalDate = approvalDt;
                    }

                    repository.TrySave<Profile>();

                    return true;
                }

                return false;
            };
        }      

    }
}
